do "E:\yungyu\lottery_baby\do\set_environment.do"

clear
set more off

global control1 "i.pers_gender i.houhld_resid_cd pers_income_pre1 pers_asset_pre1 pers_earnings_pre1 pers_labor_pre1 married_pre1"
global control2 "totbaby_pre1"
global control3 "pre*redeem*"

use "$wdata\project_lottery_fertility_b3a6_first_5k.dta", clear
	
drop if prize10M > 5
	
replace norm_year = norm_year + 3		
gen tot_asset = pers_asset + spouse_asset

foreach y in totbaby { 
	sum `y' if current == 0 & norm == 2
	loc m0 = r(mean)
	sum `y' if current == 0 & norm == 9
	loc m1 = r(mean)
	loc bt = `m1' - `m0'
	loc bt: dis %9.3f `bt'
		
	sum tot_asset if current == 0 & norm == 2
	loc m0t = r(mean)
	sum tot_asset if current == 0 & norm == 9
	loc m1t = r(mean)
	loc bt_wt = `m1t' - `m0t' //Baseline trend in Total wealth
	loc m0t: dis %9.3f `m0t'
	loc bt_wt: dis %9.3f `bt_wt'
	
	cap rm "$table/temp/Tab2.txt"
	cap rm "$table/temp/Tab2.xls"

	** Basic DDD
	reghdfe `y' currentxprizexp* prize10M c.prize10M#i.norm c.prize10M#1.current, a(norm#current) cl(houseid)
	outreg2 using "$table/temp/Tab2.xls" , append bd(3) sd(3) nocon keep(currentxprize*) ctitle(Col1) addtext(Baseline Trend, `bt', Baseline Wealth, `m0t', Baseline Trend in Wealth, `bt_wt')
	
	** Basic DDD + age FE
	reghdfe `y' currentxprizexp* prize10M c.prize10M#i.norm c.prize10M#1.current i.age, a(norm#current) cl(houseid)
	outreg2 using "$table/temp/Tab2.xls" , append bd(3) sd(3) nocon keep(currentxprize*) ctitle(Col2)

	** Add year fixed effects 
	reghdfe `y' currentxprizexp* prize10M c.prize10M#i.norm c.prize10M#1.current i.age, a(norm#current year) cl(houseid)
	outreg2 using "$table/temp/Tab2.xls" , append bd(3) sd(3) nocon keep(currentxprize*) ctitle(Col3)

	** Add individual control
	reghdfe `y' currentxprizexp* prize10M c.prize10M#i.norm c.prize10M#1.current i.age $control1, a(norm#current year) cl(houseid)
	outreg2 using "$table/temp/Tab2.xls" , append bd(3) sd(3) nocon keep(currentxprize*) ctitle(Col4)
	
	** Add individual control 2
	reghdfe `y' currentxprizexp* prize10M c.prize10M#i.norm c.prize10M#1.current i.age $control1 $control2, a(norm#current year) cl(houseid)
	outreg2 using "$table/temp/Tab2.xls" , append bd(3) sd(3) nocon keep(currentxprize*) ctitle(Col5)
	
	** Add individual control 3
	reghdfe `y' currentxprizexp* prize10M c.prize10M#i.norm c.prize10M#1.current i.age $control1 $control2 $control3, a(norm#current year) cl(houseid)
	outreg2 using "$table/temp/Tab2.xls" , append bd(3) sd(3) nocon keep(currentxprize*) ctitle(Col6)

}

import delimited using "$table/temp/Tab2.txt", clear stringcols(_all) stripquotes(yes)
export excel "$table/Tables.xlsx", sheet("Tab2") sheetreplace
